// import React from 'react';
// import { Button } from 'antd';

import { useEffect, useState } from 'react';
import { setRefreshToken, setToken } from './common/net';
import ContentView from './item';
import { message } from 'antd';
import { PluginFactory } from './common/setup';
import appState from './sotre';
import styles from './app.module.less';
import 'antd/dist/antd.css';
import { useRequest } from 'ahooks';
import { GetWorkFormVerFile } from './api/work';

const App = () => {
  const fileConfigHook = useRequest(GetWorkFormVerFile, { manual: true });

  useEffect(() => {
    // console.log('hhh-xxx', location);
    const storagePath = localStorage.getItem('search_params');
    console.log('storagePath', storagePath);
    // localStorage.removeItem('search_params');
    const urlParams = new URLSearchParams(storagePath);
    const token = urlParams?.get('access_token');
    const pgroupId = urlParams?.get('pgroup_id') || 'L001';
    const formId = urlParams?.get('form_id');
    const formVerId = urlParams?.get('form_ver_id') || '';
    const refreshToken = urlParams?.get('refresh_token');
    if (token) {
      setToken(token);
    }
    if (refreshToken) {
      setRefreshToken(refreshToken);
    }
    window.formVerId = formVerId!;
    const factory = new PluginFactory();
    appState.factory = factory;
    appState.formVerId = formVerId;
    appState.pgroupId = pgroupId;

    fileConfigHook.run('1', formVerId);
  }, []);
  return (
    <div className={styles.app}>
      <ContentView />
    </div>
  );
};

export default App;
